//
//  TransactionProtocol.swift
//  XHWalletUtils
//
//  Created by xinph on 2020/5/28.
//  Copyright © 2020 xinph. All rights reserved.
//

import Foundation

/// 交易体
/// 根据后台接口再调整
public protocol TransactionConvertible {
    var nonce: Float? { get set }
    var gasPrice: Int64 { get set }
    var gasLimit: Int64 { get set }
    
    var proposalId: Int { get set }
    
    var to: AddressConvertible { get set }
    var value: Int64 { get set }
    var data: Data? { get set }
    var chainID: Int? { get set }
}

/// 交易结果
/// 根据后台接口再调整
public protocol TransactionResult {
    var transaction: TransactionConvertible { get set }
    var hash: String { get set }
}

public protocol TransactionProtocol {
    
    /// 发送签名后的交易给服务器
    /// - Parameters:
    ///   - ts: 未签名交易
    ///   - password: 密码
    ///   - from: 用来签名的账户地址
    func sendTransactionUnSigned(_ ts: TransactionConvertible, password: String, from: AddressConvertible) -> Observable<TransactionResult>
}

public protocol TransactionRPCProtocol {
    /// 自定义合约发送eth
    /// - Parameters:
    ///   - from: 钱包地址
    ///   - to: 目标地址
    ///   - money: 转账金额
    ///   - password: keystore密码
    ///   - closure: 转账结束回执
    func writeContract(_ from: AddressConvertible, to: AddressConvertible, money: String, password: String, closure: @escaping (Result<TransactionSendingResult>) -> Void)

    /// 根据交易哈希获取交易详情
    /// - Parameters:
    ///   - txhash: 交易哈希
    ///   - closure: 交易回执
    func getTransactionDetails(_ txhash: String, closure: @escaping (Result<TransactionDetails>) -> Void)
}
